<?php
class Main extends GetData{

	private $daten;
	public $System;

	public function __construct($match){
		$this->daten = $match;
	}

	public function getWort(RainTPL $design){
		if($design->url != '/'){
			HTTP::redirect(ConfigFile::Get('404'));
		}
		
		$design->assign(CSS_VAR,"startseite");
		$design->assign(JS_VAR,"jsHome");		
		
		if(isset($_SESSION['UserName'])){
		    parent::GetData();
		    
		    $design->assign("USER",$this->ActivUser);
		    
		    if(!array_key_exists('UserCityId',$_SESSION)){
    		    $ipLite = new ip2location_lite;
                $ipLite->setKey(ConfigFile::Get('ip2location_api_key'));
                 
                //Get errors and locations
                $locations = $ipLite->getCity($_SERVER['REMOTE_ADDR']);
                $errors = $ipLite->getError();                
		        
                if($locations){
                    $design->assign ('location',$locations);
                    $DbCity = new Db_City();
                    #$citys = $DbCity->getCitysByRadius($locations['latitude'],$locations['longitude'],10);        
                    
                    if(isset($citys)){
                        $design->assign ('citys',$citys);
                    }
                }
		    }else{		        
		        $design->assign ('userlocation',$_SESSION['UserCity']);
		    }
		    
		    ##$Db_city = new Db_City();
		    ##$city = $Db_city->getCity($_SESSION['UserCityId']);
		    
		    $DbUserRelation = new Db_user_relation;
		    $UserRelations = $DbUserRelation->getUserRelation($this->ActivUser->id);
		    
		    $RelationInvitation = $DbUserRelation->getRelationInvitation($this->ActivUser->id);
		    		    
		    $design->assign ('UserRelations',$UserRelations);
		    $design->assign ('RelationInvitation',count($RelationInvitation));
		    
		    if( $cache = $design->cache( $design->ln.'/home', $expire_time = 0 ) )
    	    {
    	 	    echo $cache;
    	    }
    	    else
    	    {
    	 	    $design->draw( $design->ln.'/home' );
    	    }
		}else{
    		if( $cache = $design->cache( $design->ln.'/main', $expire_time = 0 ) )
    	    {
    	 	    echo $cache;
    	    }
    	    else
    	    {
    	 	    $design->draw( $design->ln.'/main' );
    	    }
		}		
	}

}
?>